1. Field of the Invention
The present invention relates to calculating devices such as a portable computer, a function calculator, a pocket computer, etc. and more particularly to calculating devices designed to get a solution by the iterative method using an equation and initial value inputted by an operator.
2. Description of the Prior Art
In the iteration method such as Newton's method and the steepest descent method, when a solution, a maximum value, or a minimum value (these values are referred to as simply "solution" below) is sought for, calculations are repeated using an initial value X.sub.0. More specifically, from the initial value X.sub.0 a next value X.sub.1 is calculated, and then from the value X.sub.1 a next value X.sub.2 is calculated. A similar iterative operation is repeatedly performed until a solution is achieved. In this case, whether the solution can be achieved or not depends on the initial value. However, different equations require different initial values to achieve their respective solutions and it is therefore impossible to set the initial value in general.
FIG. 1 is a flow chart showing the execution of an application for use of the iterative method in a prior art calculating device. As shown in this figure, when this application is carried out in the prior art calculating device, an operator inputs an equation for calculation at step S201, and then inputs an initial value of a variable contained in the equation. Further, if necessary, an operator also inputs a range within which a solution is expected to exist at step S201. Such a range is referred to as "solution existing range" below. Next, at step S203, the arithmetic processing is actually done using the input equation and the input initial value. If a solution is achieved, the solution is displayed. However, when in error, an error message is displayed at step S204.
FIG. 2 shows the procedures of the arithmetic processing executed at step S203 of FIG. 1.
At first, at step S211, various work areas used for the arithmetic processing are initialized. Then, at step S212, the number of times to change the initial value in failure of the iterative operation (i.e., the loop count) is set to the counter "KAISU". For example, the loop count is 9. After that, the iterative operation is executed at step S213. FIG. 3 is a flowchart showing the concrete procedure of the iterative operation executed at step S213 of FIG. 2.
In the iterative operation processing of the prior art calculating device, various work areas used for the iterative operation are initialized at step S221, and the maximum trial number of the iterative operation (the loop count is set to the counter "count" at step S222. Thereafter, the next value X.sub.n+1 is calculated from the current value X.sub.n at step S223. For example, in the case of Newton' method, the following expression is calculated, EQU X.sub.n+1 =X.sub.n -f(X.sub.n)/f'(X.sub.n) (1)
where f(X.sub.n) is a value obtained by substituting X.sub.n for a variable X in the function f(X) and f'(X.sub.n) is a value obtained by substituting X.sub.n for X in the derivative of f(X).
When the calculation results in an error at step S224, this iterative operation is finished. On the other hand, if no error has happened and the next value X.sub.n+1 has been calculated, it is discriminated at step S225 whether or not the value X.sub.n+1 is a solution to be expected. If the value X.sub.n+1 reaches a solution, the iterative operation is ended. On the other hand, if the value X.sub.n+1 does not reach a solution, one is subtracted from the value of "count" at step S226 and the program returns to step S223. Thus, the loop of steps S223-S226 is repeatedly executed until the solution is achieved or the value of the counter "count" becomes zero.
Next, at step S214 (FIG. 2), it is judged whether an operation error has happened in the series of iterative operations. If there is no error and the solution is correctly calculated, or if a grammatical error (a syntax error) has happened, the arithmetic processing of S203 is ended without any further operations.
If an operation error has occurred, the value of the counter "KAISU" is decreased by one, and when the value of "KAISU" becomes zero at step S215, the arithmetic processing is ended. If the value of "KAISU" is not zero, a new initial value is generated such that the new initial value falls within the solution existing range at step S216. FIG. 4 shows a flowchart of the concrete procedure of generating the new initial value executed at step S216.
Referring to FIG. 4, supposing that the upper limit value of the solution existing range input by the operator is R.HANI, that the lower limit value is L.HANI and that new initial value is set as X.sub.0, a value which is equal to the 8 equally divided part of the difference or length between L.HANI and R.HANI is set to X.sub.0 at step S231. Next, at step S232, a value of (9-KAISU) is input into the counter "Acc". That is to say, each time a new initial value is generated, the value of the counter "Acc" is increased by one up to 9. Next, at step S233, a value of (L.HANI+X.sub.0 * Acc) is calculated and stored in X.sub.0. By so doing, initial values from L.HANI to R.HANI are given in order from the left side (the smaller side), and the loop of S213-S216 is repeatedly executed until the value of "KAISU" becomes equal to zero. FIG. 5A shows the order in which the initial values from L.HANI to R.HANI are generated and the numbers 1-9 in this figure show the order.
Then as mentioned before, if the solution is given, the solution is displayed, and if the solution could not be achieved, an error message is displayed at S204 of FIG. 1.
FIGS. 6A, 6B, 6C, 6D and 6E show display examples when Newton's method is applied in the common function calculator.
As shown in FIG. 6A, when the application using Newton's method is started, the screen displays ""EQUATION?" to invite the operator to input an equation to be solved. The operator, then, inputs the equation "X.sup.2 -3=0" and a value of zero as an initial value of the variable X in the equation. These input data are displayed as shown in FIGS. 6B and 6C. If necessary, the operator changes the display screen to input a solution existing range and inputs [a,b]. In this example, a=-1.times.10.sup.10, b=1.times.10.sup.10.
Then the calculator executes the arithmetic processing and displays the result, X=1.7320508, as shown in FIG. 6E. In this example, the screen indicates whether the arithmetic processing was successfully done by displaying values of the left side L and the right side R of the equation simultaneously.
But the above-mentioned prior art calculating device has the following problems.
(1) In the application to get the solution of the equation by Newton's method, equations such as (X-2).sup.2 +10=0 cannot give a solution, because the equation does not have a solution of a real number. In this case, because the iterative operation is repeated a predetermined number of times and stopped finally without giving a solution, time is wasted.
(2) When solving an equation of log X=0 in the application to get the solution of the equation by Newton's method, because the value of the left side of this equation is defined only for X&gt;0, an operation error will occur if the value of X once comes to be equal to or smaller than zero in the course of the calculation. In the case that solution existing range is divided into eight parts and that the initial value is given in order from the left side (the smaller side) as shown in FIG. 5A, if the solution existing range from -10 to 10 is set, the iterative operations for the first to fifth initial values, -10, -7.5, -5, -2.5, will result in error, and the sixth initial value 2.5 will give a solution at last. As is obvious from this, it can be said that when an error happens for some initial value, other initial values close to the initial value that has caused the error will also cause an error. Therefore, in the prior art method to give the initial values from the left side to the right side in order, it will take a long time to achieve a solution once an error is caused.
(3) When an error happens in the course of calculation, the prior art calculating device only displays an error message or again executes the iterative operation with another initial value. That is, no means for supplementing the setting of initial values after the error occurrence are provided to the prior art calculating device. Therefore the prior art calculating device cannot achieve a solution in some cases even when there is a solution, which might be achieved with an initial value generated in a different way from an initial value causing an error.
Conventional calculators and function calculators can use only a numerical memory whose memory areas each has a name consisting of a single character (for example, A, B, etc.). Therefore multi-character names of variables as used in the formula tables and the text books etc. cannot be used to input and calculate mathematical expressions. On the other hand, in a pocket computer which is programmable, multi-character names of variables can be used in the program but an operator has to do complicated operations because the program must be prepared in accordance with program rules and executed. Moreover, from the point of view of the control side, there is a problem that in a case where variables consisting of several characters are used, memory areas for storing numerical values and names representing the numerical values must be secured in, for example, the memory area for storing programs. Also, complicated control operations are required to analyze, store, and call a plurality of data codes.